package com.ax.center.controller;

import com.ax.center.annotation.Logging;
import com.ax.center.dto.ApiResponse;
import com.ax.center.entity.RoleAuth;
import com.ax.center.service.RoleAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zy
 * @date 2023/7/6 16:16
 */

@RestController
@RequestMapping(value = "roleAuthService")
@Api(tags = "角色权限服务")
@CrossOrigin(origins = "http://localhost:5173")
public class RoleAuthController {
    @Autowired
    private RoleAuthService roleAuthService;


    @PostMapping("/无效的请求")
    public void test(@RequestBody RoleAuth roleAuth){
        return;
    }

    @Logging(description = "查询角色对应的权限")
    @GetMapping(value = "/queryAuthByRoleId/{roleId}")
    @ApiOperation("查询角色对应的权限")
    public ApiResponse queryAuthByRoleId(@PathVariable("roleId") Long roleId) {
     return roleAuthService.queryAuthByRoleId(roleId);

    }

    @Logging(description = "插入角色权限")
    @PostMapping(value = "/insertOne/{id}/{authid}")
    @ApiOperation("插入角色权限")
    public ApiResponse insertOne(@PathVariable("id") Long id, @PathVariable("authId") Long authId) {
        ApiResponse response = roleAuthService.insertOne(id, authId);
        return response;
    }

    @Logging(description = "删除角色权限")
    @DeleteMapping(value = "/deleteOne/{id}")
    @ApiOperation("删除角色权限")
    public ApiResponse deleteOne(@PathVariable("id") Long id) {
        ApiResponse response = roleAuthService.deleteOneByRoleId(id);
        return response;
    }
}

